home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWPart / Sources / FWPrmise.cpp < prev    next >
Encoding:
Text File  |  1996-08-16  |  5.7 KB  |  202 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWPrmise.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFrameW.hpp"
  11.  
  12. #ifndef FWPRMISE_H
  13. #include "FWPrmise.h"
  14. #endif
  15.  
  16. #ifndef FWPART_H
  17. #include "FWPart.h"
  18. #endif
  19.  
  20. #ifndef FWFRAME_H
  21. #include "FWFrame.h"
  22. #endif
  23.  
  24. #ifndef FWCLNINF_H
  25. #include "FWClnInf.h"
  26. #endif
  27.  
  28. #ifndef FWINTER_H
  29. #include "FWInter.h"
  30. #endif
  31.  
  32. #ifndef FWLNKSRC_H
  33. #include "FWLnkSrc.h"
  34. #endif
  35.  
  36. // ----- OS Layer Includes -----
  37.  
  38. #ifndef FWBARRAY_H
  39. #include "FWBArray.h"
  40. #endif
  41.  
  42. // ----- Foundation Layer Includes -----
  43.  
  44. #ifndef FWMEMORY_H
  45. #include "FWMemory.h"
  46. #endif
  47.  
  48. #ifndef SLPRISTR_H
  49. #include "SLPriStr.h"
  50. #endif
  51.  
  52. // ----- OpenDoc Includes -----
  53.  
  54. #ifndef SOM_ODClipboard_xh
  55. #include <Clipbd.xh>
  56. #endif
  57.  
  58. #ifndef SOM_ODSession_xh
  59. #include <ODSessn.xh>
  60. #endif
  61.  
  62. #ifndef SOM_ODStorageUnitView_xh
  63. #include <SUView.xh>
  64. #endif
  65.  
  66. #ifndef SOM_Module_OpenDoc_StdProps_defined
  67. #include <StdProps.xh>
  68. #endif
  69.  
  70. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  71. #include <StdTypes.xh>
  72. #endif
  73.  
  74. #ifndef SOM_ODDraft_xh
  75. #include <Draft.xh>
  76. #endif
  77.  
  78. #if defined(__MWERKS__) && GENERATING68K
  79. // A hack to work around a bug
  80. #pragma import list somGetGlobalEnvironment
  81. #endif
  82.  
  83. //========================================================================================
  84. // RunTime Info
  85. //========================================================================================
  86.  
  87. #ifdef FW_BUILD_MAC
  88. #pragma segment fwpart2
  89. #endif
  90.  
  91. //========================================================================================
  92. //    Template Instantiations
  93. //========================================================================================
  94.  
  95. FW_DEFINE_AUTO_TEMPLATE(FW_TOrderedCollectionIterator, FW_CPromise)
  96. FW_DEFINE_AUTO_TEMPLATE(FW_TOrderedCollection, FW_CPromise)
  97.  
  98. #ifdef FW_USE_TEMPLATE_PRAGMAS
  99.  
  100. #pragma template_access public
  101. #pragma template FW_TOrderedCollection<FW_CPromise>
  102. #pragma template FW_TOrderedCollectionIterator<FW_CPromise>
  103.  
  104. #endif
  105.  
  106. //========================================================================================
  107. //    class FW_CPromise
  108. //========================================================================================
  109.  
  110. //----------------------------------------------------------------------------------------
  111. //    FW_CPromise::FW_CPromise
  112. //----------------------------------------------------------------------------------------
  113.  
  114. FW_CPromise::FW_CPromise(Environment*ev, FW_EStorageKinds storageKind, FW_CCloneInfo* cloneInfo) :
  115.     fScopeFrame(cloneInfo->GetScopeFrame(ev)),
  116.     fDataInterchange(cloneInfo->GetDataInterchange(ev)),
  117.     fStorageKind(storageKind),
  118.     fUpdateID(0),
  119.     fPromiseCount(0)
  120. {
  121.     FW_ASSERT(fStorageKind != FW_kLinkStorage);
  122.     FW_ASSERT(fStorageKind != FW_kPartStorage);    // can promise on the part storage
  123.     FW_ASSERT(fStorageKind != FW_kFileStorage);    // can promise on a file storage
  124.  
  125.     fUpdateID = fScopeFrame->GetPart(ev)->GetSession(ev)->GetClipboard(ev)->GetUpdateID(ev);    
  126. }
  127.  
  128. //----------------------------------------------------------------------------------------
  129. //    FW_CPromise::FW_CPromise
  130. //----------------------------------------------------------------------------------------
  131.  
  132. FW_CPromise::FW_CPromise(Environment*ev, FW_CLinkSource* linkSource, FW_CCloneInfo* cloneInfo) :
  133.     fScopeFrame(cloneInfo->GetScopeFrame(ev)),
  134.     fDataInterchange(cloneInfo->GetDataInterchange(ev)),
  135.     fStorageKind(FW_kLinkStorage),
  136.     fUpdateID(0),
  137.     fLinkSource(linkSource),
  138.     fPromiseCount(0)
  139. {
  140.     FW_ASSERT(fLinkSource != NULL);
  141.     fLinkSource->PrivSetPromise(ev, this);
  142. }
  143.  
  144. //----------------------------------------------------------------------------------------
  145. //    FW_CPromise::~FW_CPromise
  146. //----------------------------------------------------------------------------------------
  147.  
  148. FW_CPromise::~FW_CPromise()
  149. {
  150.     Environment* ev = somGetGlobalEnvironment();
  151.     if (fStorageKind == FW_kLinkStorage)
  152.     {
  153.         FW_ASSERT(fLinkSource != NULL);
  154.         fLinkSource->PrivSetPromise(ev, NULL);
  155.     }
  156.     
  157.     fDataInterchange->PrivPromiseDeleted(ev, this);
  158. }
  159.  
  160. //----------------------------------------------------------------------------------------
  161. //    FW_CPromise::Promise
  162. //----------------------------------------------------------------------------------------
  163.  
  164. void FW_CPromise::Promise(Environment* ev, ODStorageUnit* storageUnit, ODPropertyName propertyName, ODValueType valueType)
  165. {    
  166.     fDataInterchange->PrivPromise(ev, this, storageUnit, propertyName, valueType);
  167.     fPromiseCount++;
  168. }
  169.  
  170. //----------------------------------------------------------------------------------------
  171. //    FW_CPromise::PrivHandleFulfillPromise
  172. //----------------------------------------------------------------------------------------
  173.  
  174. long FW_CPromise::PrivHandleFulfillPromise(Environment* ev, ODStorageUnitView* promiseSUView)
  175. {
  176.     ODDraft* fromDraft = fScopeFrame->GetPart(ev)->GetDraft(ev);
  177.     ODDraft* dstDraft = promiseSUView->GetStorageUnit(ev)->GetDraft(ev);
  178.  
  179.     // Get the cloneKind from the kODPropCloneKindUsed property, if it's available
  180.     ODCloneKind cloneKind;
  181.     if (FW_SUExistsThenFocus(ev, promiseSUView->GetStorageUnit(ev), kODPropCloneKindUsed, kODCloneKind) )
  182.     {
  183.         FW_CByteArray byteArray;
  184.         promiseSUView->GetStorageUnit(ev)->GetValue(ev, sizeof(ODCloneKind), byteArray);
  185.         byteArray.CopyBuffer(&cloneKind, sizeof(ODCloneKind));
  186.     }
  187.     else
  188.         cloneKind = (fStorageKind == FW_kLinkStorage) ? kODCloneToLink : kODCloneCopy;
  189.  
  190.     FW_CAcquireODPropertyName propertyName(ev, promiseSUView);
  191.     FW_CAcquireODType valueType = promiseSUView->GetType(ev);    
  192.  
  193.     FW_CCloneInfo cloneInfo(ev, fromDraft, fScopeFrame, cloneKind);    
  194.     cloneInfo.BeginClone(ev, dstDraft);
  195.  
  196.     FulfillPromise(ev, promiseSUView, propertyName, valueType, &cloneInfo);
  197.  
  198.     cloneInfo.EndClone(ev);
  199.     
  200.     return --fPromiseCount;
  201. }
  202.